package com.study.callBack;


import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ThreadPoolExecutor;

public class ThreadTest {

//    static CyclicBarrier cyclicBarrier = new CyclicBarrier(3, new Runnable() {
//        public void run(){
//
//            System.out.println("三个人都已到达会议室");
//        }
//    });
//
//
//    public static void main(String[] args) {
//        for (int i = 0; i < 3; i++) {
//            final int finalI = i;
//            new Thread(new Runnable() {
//                public void run() {
//                    try {
//                        Thread.sleep((long) (Math.random()*5000));
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                    System.out.println("第"+Thread.currentThread().getName()+"个人到达会议室");
//                }
//            }, String.valueOf(finalI)).start();
//        }
//
//    }


    static CyclicBarrier cyclicBarrier = new CyclicBarrier(10);


    public static void main(String[] args) {
        for (int i = 0; i < 9; i++) {
            new Thread(()-> {
                try {
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName() + "个人来到");
                    cyclicBarrier.await();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();
        }
//        try {
//            Thread.sleep(10000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        System.out.println("**************" + cyclicBarrier.getNumberWaiting());
//        try {
//            cyclicBarrier.await();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } catch (BrokenBarrierException e) {
//            e.printStackTrace();
//        }
        System.out.println("======================都来了 开会");
        System.out.println("**************" + cyclicBarrier.getNumberWaiting());

    }
}




